package cn.tedu.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

/**
 * 注销用户功能:执行DML语句[delete]
 * 请输入用户名:Tony
 * 返回结果 | 注销失败
 */
public class JDBCDemo03 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class cls = Class.forName("com.mysql.cj.jdbc.Driver");
        Connection conn = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root", "root");
        Statement statement = conn.createStatement();
        Scanner sc = new Scanner(System.in);
        String username = sc.nextLine();
        String sql = "delete from userinfo where username = '"+username+"'";
        int i = statement.executeUpdate(sql);
        if(i > 0){
            System.out.println("账号注销成功");
        }else {
            System.out.println("账号注销失败");
        }
        conn.close();
    }
}
